#!/bin/sh

# keep old pwd
OLDPWD=$(pwd)
cd $(dirname $0)

# if check is the first param we search for a process with java and heatctrl
# if there is one all is fine
if [ "$1" = "check" ] ; then
  if [ `ps fax | grep java | grep heatctrl | wc -l` -ne 0 ] ; then
   exit 0;
  fi
fi

# remove the old process
killall -q java

# start the java-process as deamon
nohup java -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -cp lib/servlet-api-2.5-20081211.jar:lib/jetty-6.1.26.jar:lib/jetty-util-6.1.26.jar:lib/junit-4.8.2.jar:lib/commons-lang3-3.0.jar:lib/jdom-1.1.jar:lib/mysql-connector-java-5.1.14.jar:lib/commons-dbcp-1.4.jar:lib/heatctrl-0.9-SNAPSHOT.jar:lib/mail-1.4.1.jar:lib/commons-pool-1.5.4.jar:lib/activation-1.1.jar:lib/log4j-1.2.14.jar:lib/commons-codec-1.3.jar:lib/json-smart-1.2.jar:lib/pi4j-core-0.0.5.jar x7.heatctrl.Runner > /dev/null 2> /dev/null &

# go back to the old pwd
cd $OLDPWD
